package main

import (
	"encoding/json"
	"fmt"
)

type copy1 struct {
	Id   float64
	Name string
}

type copy2 struct {
	Id   float64
	Name string
}

type copy3 struct {
	Id   int
	Name string
	c3   string
}

func main() {
	c1 := copy1{Id: 1.2, Name: "111"}
	c2 := c1
	c2.Id = 1.0

	fmt.Println(c1)
	fmt.Println(c2)

	c3 := copy2(c2)
	fmt.Println(c3)

	// 字段一样可以转，字段不一样不可以转
	// cc := copy3(c1)
	// fmt.Println(cc)

	// 类型兼容的可以转，不兼容字段没法转，只能变默认零值，总体上不会报错
	buf, err := json.Marshal(c1)
	fmt.Println("c1 Marshal err:", err)
	var cc copy3
	json.Unmarshal(buf, &cc)
	fmt.Println(cc)

	buf, err = json.Marshal(c2)
	fmt.Println("c2 Marshal err:", err)
	json.Unmarshal(buf, &cc)
	fmt.Println(cc)
}
